package com.barnabot.hallofgames.dao;

import com.barnabot.hallofgames.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.Menu;
 
public class SQLiteInput extends Activity implements OnClickListener{
 
    Button sqlUpdate;
    Button sqlView;
 
    //EditText sqlName;
    //EditText sqlAge;
    
    EditText sqlGameName;
    EditText sqlGameDesc;
    EditText sqlGameGen;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_new_game);
 
        sqlUpdate = (Button) findViewById(R.id.bSQLUpdate);
        sqlView  = (Button) findViewById(R.id.bSQLView);
 
        sqlGameName  = (EditText) findViewById(R.id.etGameName);
        sqlGameDesc    = (EditText) findViewById(R.id.etGameDesc);
        sqlGameGen    = (EditText) findViewById(R.id.etGameGen);
 
        sqlUpdate.setOnClickListener(this);
        sqlView.setOnClickListener(this);
    }
 
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch (arg0.getId()){
        case R.id.bSQLUpdate:
 
            boolean work = true;
 
            try{
 
            String gameName = sqlGameName.getText().toString();
            String gameDesc = sqlGameDesc.getText().toString();
            String gameGen = sqlGameGen.getText().toString();
 
            SQLiteManage entry = new SQLiteManage(SQLiteInput.this);
 
            entry.open();
            //entry.createEntry(gameName, gameDesc);
            entry.createEntry(gameName, gameDesc, gameGen);
            entry.close();
 
            }catch (Exception e){
                work = false;
                String erro = e.toString();
                Dialog d = new Dialog(this);
                d.setTitle("Erro!");
                TextView tv = new TextView(this);
                tv.setText(erro);
                d.setContentView(tv);
                d.show();
 
            }finally{
                if (work == true){
                    Dialog d = new Dialog(this);
                    d.setTitle("Carregado!");
                    TextView tv = new TextView(this);
                    tv.setText("Com sucesso.");
                    d.setContentView(tv);
                    d.show();
                }
            }
            break;
        case R.id.bSQLView:
            Intent i = new Intent("com.barnabot.hallofgames.dao.SQLVIEW");
            startActivity(i);
            break;
        }
    }
 
}